Page({
  data: {
    username: '',
    password: '',
    confirmPassword:'',
    InvitationCode:'',
    info:{}
  },

  // 获取输入用户名  
  usernameInput: function (e) {
    this.setData({
      username: e.detail.value
    })
  },

  // 获取输入密码  
  passwordInput: function (e) {
    this.setData({
      password: e.detail.value
    })
  },

  // 获取确认密码  
  confirmPasswordInput: function (e) {
    this.setData({
      confirmPassword: e.detail.value
    })
  },

  // 获取邀请码密码  
  InvitationCodeInput: function (e) {
    this.setData({
      InvitationCode: e.detail.value
    })
  },

  // 注册  
  register: function () {
    var that = this;
    if (this.data.username.length == 0 || this.data.password.length == 0 || this.data.confirmPassword.length == 0 || this.data.InvitationCode.length == 0) {
      wx.showToast({
        title: '框框不能为空',
        icon: 'loading',
        duration: 2000
      })
      return;
    }
    if (this.data.confirmPassword != this.data.password){
      wx.showToast({
        title: '两次密码不一致',
        icon: 'loading',
        duration: 2000
      })
      return;
    }
    wx.request({
      url: getApp().globalData.ADMIN_API_HOST+"/register",
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      method: "POST",
      data: { 
        account: this.data.username, 
        password: this.data.password, 
        code: this.data.InvitationCode 
      },
      fail: function () {
        wx.showToast({
          title: '网络请求失败',
          icon: 'loading',
          duration: 2000
        })
      },
      success: function (res) {
        if(res.data.isSuccess){
          that.setData({
            info: res.data
          });
          wx.showToast({
            title: '注册成功',
            icon: 'success',
            duration: 2000
          });
          wx.redirectTo({
            url: '../login/login',
          })
        }else{
          wx.showModal({
            title: '提示',
            content: res.data.msg,
            showCancel: false,
          })
        }
      },
    })
  },

  phoneCall: function () {
    wx.makePhoneCall({
      phoneNumber: '02154590625',
    })
  },


})   